<?php
namespace Crm\Table;

use Zend\Db\Sql\Select;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Expression;

class PowerGroupTable extends AbstractTable
{

    protected $table = 'hycrm_power_group';

    protected $id = 'id';
    
	
	public function deleteByGroupId($id){
		if(empty($id)){
			throw new \Exception("id field is invalid!");
		}
		return $this->delete(array('user_group_id'=>$id));
		
	}
	
	public function addItem($data){
		
		$item = array(
			'user_group_id'=>$data['user_group_id'],
			'power_id'=>$data['power_id'],
		);
		
		$this->insert($item);
		$id = $this->lastInsertValue;

		return $id;
	}

	public function getPowerByGroupId($group_id){
	
	    $select = new Select(array('pg' =>$this->getTable()));
	    
	    $select->join(
	        array('pm' => 'hycrm_power_manage'),
	        'pg.power_id = pm.power_id',
	        array('power_action') ,
	        $select::JOIN_LEFT
	        );
	    $select->where(array('pg.user_group_id' => $group_id));
	    $rowset = $this->selectWith($select);
	    $list = $rowset->toArray();
	    
	    return $list;
	}


}